package networkSimulation.simulation.virus.monitor

import networkSimulation.simulation.virus.InfectablePerson
import networkSimulation.framework.{Edge, Graph}
import networkSimulation.monitor.Monitor

/**
 * Monitor the spread of a virus.
 *
 * @author  Tim Caljé
 *          Jeroen De Raedt
 *          Jorick Van Aken
 */
class VirusSpreadMonitor[Method, Pub](name : String,graph : Graph[InfectablePerson, Edge[InfectablePerson]]) extends Monitor[Method, Pub, InfectablePerson, Edge[InfectablePerson]](name, graph) {

  /**
   * Custom implementation of the reaction to a notification of a publishing event of a Publisher.
   */
  @Override
  def notify(pub: Pub,  event: Method) {
    val nrInfected = graph.nodes.filter(n =>  n.asInstanceOf[InfectablePerson].isDead == true).toList.size
    if (nrInfected > (graph.nodes.size/2)) {  // if over 50% of the population is sick: start giving antidotes which make them immune
      for(node: InfectablePerson <- graph.nodes.filter(n => !n.infected)) {
        node.immune = true
      }
    }
  }

}